class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;
    int k;
    int add;
    vector<vector<int>> combinationSum(vector<int>& c, int target) {
        k=target;
        dfs(c,0);
        return ret;
    }

    void dfs(vector<int>& nums,int pos)
    {
        if(add>k||add==k)
        {
            if(add==k)
            {
                ret.push_back(path);
            }
            return;
        }
        for(int i=pos;i<nums.size();++i)
        {
            path.push_back(nums[i]);
            add+=nums[i];
            dfs(nums,i);
            path.pop_back();
            add-=nums[i];
        }
    }
};
